package com.fsnbigdata.domain;

import com.fsnbigdata.util.ChineseInital;
import io.springlets.format.EntityFormat;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Index;
import org.hibernate.validator.constraints.Length;
import org.springframework.roo.addon.javabean.annotations.RooEquals;
import org.springframework.roo.addon.javabean.annotations.RooJavaBean;
import org.springframework.roo.addon.javabean.annotations.RooToString;
import org.springframework.roo.addon.jpa.annotations.entity.JpaRelationType;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity;
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaRelation;
import org.springframework.util.Assert;

/**
 * = Ecosystem
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJavaBean
@RooToString
@RooJpaEntity(entityFormatExpression = "#{name}")
@RooEquals(isJpaEntity = true)
@Entity
@EntityFormat("#{name}")
public class Ecosystem {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @Version
    private Integer version;

    /**
     * 名称
     */
    @NotNull
    @Size(min = 1, max = 255,message = "生态环境名称长度必须0-255之间")
    private String name;

    /**
     * 拼音首字母
     */
    @Index(name="Ecosystem_initial")
    private String initial;

    /**
     * 行政区域
     */
    @Length(min = 0, max = 255,message = "生态环境行政区域长度必须0-255之间")
    private String administrativeLocation;

    /**
     * 类型
     */
    private Integer type;

    /**
     * 面积
     */
    @Length(min = 0, max = 255,message = "生态环境面积长度必须0-255之间")
    private String area;

    /**
     * 维护对象
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String maintained;

    /**
     * 类型
     */
    @Length(min = 0, max = 255,message = "生态环境类型长度必须0-255之间")
    private String category;

    /**
     * 级别
     */
    @Length(min = 0, max = 255,message = "生态环境级别长度必须0-255之间")
    private String currentLevel;

    /**
     * 主管部门
     */
    @Length(min = 0, max = 255,message = "生态环境主管部门长度必须0-255之间")
    private String administrativeDepartment;

    /**
     * 始建时间
     */
    @Length(min = 0, max = 255,message = "生态环境始建时间长度必须0-255之间")
    private String createDate;

    /**
     * 批准机关
     */
    @Length(min = 0, max = 255,message = "生态环境批准机关长度必须0-255之间")
    private String approver;

    /**
     * 现有级别批准时间
     */
    @Length(min = 0, max = 255,message = "生态环境现有级别批准时间长度必须0-255之间")
    private String currentLevelApproveDate;

    /**
     * 经纬度范围
     */
    @Length(min = 0, max = 255,message = "生态环境经纬度范围长度必须0-255之间")
    private String coordinate;

    /**
     * 行政区域
     */
    @Length(min = 0, max = 255,message = "生态环境行政区域长度必须0-255之间")
    private String administrativeRegion;

    /**
     * 地质地貌_地质构造
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String geologyStructure;

    /**
     * 地质地貌_地层岩性
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String geologyLithology;

    /**
     * 地质地貌_地形地貌
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String geologyLandform;

    /**
     * 地质地貌_水文地质
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String geologyHydrogeology;

    /**
     * 土壤条件
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String soil;

    /**
     * 气候条件
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String climate;

    /**
     * 生物资源_森林资源
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String organismResourcesForest;

    /**
     * 生物资源_植被类型
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String organismResourcesVegeType;

    /**
     * 生物资源_植物资源
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String organismResourcesPlant;

    /**
     * 生物资源_动物资源
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String organismResourcesAnimal;

    /**
     * 旅游资源
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String tourismResources;

    /**
     * 社会经济
     */
    @Lob
    @Basic(fetch = FetchType.LAZY)
    private String socialEconomy;

    /**
     * 创建者
     */
    @Length(min = 0, max = 255,message = "生态环境创建者长度必须0-255之间")
    private String creator;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    @OneToMany(cascade = { javax.persistence.CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "ecosystem", orphanRemoval = true)
    @RooJpaRelation(type = JpaRelationType.COMPOSITION)
    @OrderBy("id")
    private Set<EcosystemImage> images = new HashSet<EcosystemImage>();

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";

    /**
     * This `equals` implementation is specific for JPA entities and uses
     * the entity identifier for it, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @param obj
     * @return Boolean
     */
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        // instanceof is false if the instance is null
        if (!(obj instanceof Ecosystem)) {
            return false;
        }
        return getId() != null && Objects.equals(getId(), ((Ecosystem) obj).getId());
    }

    /**
     * This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able
     * to identify the entity in collections after a new id is assigned to the entity, following the article in
     * https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
     *
     * @return Integer
     */
    public int hashCode() {
        return 31;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Long
     */
    public Long getId() {
        return this.id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Integer
     */
    public Integer getVersion() {
        return this.version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param version
     */
    public void setVersion(Integer version) {
        this.version = version;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getName() {
        return this.name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getInitial() {
        return this.initial;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param initial
     */
    public void setInitial(String initial) {
        this.initial = initial;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getAdministrativeLocation() {
        return this.administrativeLocation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param administrativeLocation
     */
    public void setAdministrativeLocation(String administrativeLocation) {
        this.administrativeLocation = administrativeLocation;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getArea() {
        return this.area;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param area
     */
    public void setArea(String area) {
        this.area = area;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getMaintained() {
        return this.maintained;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param maintained
     */
    public void setMaintained(String maintained) {
        this.maintained = maintained;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCategory() {
        return this.category;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param category
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCurrentLevel() {
        return this.currentLevel;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param currentLevel
     */
    public void setCurrentLevel(String currentLevel) {
        this.currentLevel = currentLevel;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getAdministrativeDepartment() {
        return this.administrativeDepartment;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param administrativeDepartment
     */
    public void setAdministrativeDepartment(String administrativeDepartment) {
        this.administrativeDepartment = administrativeDepartment;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCreateDate() {
        return this.createDate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param createDate
     */
    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getApprover() {
        return this.approver;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param approver
     */
    public void setApprover(String approver) {
        this.approver = approver;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCurrentLevelApproveDate() {
        return this.currentLevelApproveDate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param currentLevelApproveDate
     */
    public void setCurrentLevelApproveDate(String currentLevelApproveDate) {
        this.currentLevelApproveDate = currentLevelApproveDate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCoordinate() {
        return this.coordinate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param coordinate
     */
    public void setCoordinate(String coordinate) {
        this.coordinate = coordinate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getAdministrativeRegion() {
        return this.administrativeRegion;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param administrativeRegion
     */
    public void setAdministrativeRegion(String administrativeRegion) {
        this.administrativeRegion = administrativeRegion;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getGeologyStructure() {
        return this.geologyStructure;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param geologyStructure
     */
    public void setGeologyStructure(String geologyStructure) {
        this.geologyStructure = geologyStructure;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getGeologyLithology() {
        return this.geologyLithology;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param geologyLithology
     */
    public void setGeologyLithology(String geologyLithology) {
        this.geologyLithology = geologyLithology;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getGeologyLandform() {
        return this.geologyLandform;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param geologyLandform
     */
    public void setGeologyLandform(String geologyLandform) {
        this.geologyLandform = geologyLandform;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getGeologyHydrogeology() {
        return this.geologyHydrogeology;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param geologyHydrogeology
     */
    public void setGeologyHydrogeology(String geologyHydrogeology) {
        this.geologyHydrogeology = geologyHydrogeology;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getSoil() {
        return this.soil;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param soil
     */
    public void setSoil(String soil) {
        this.soil = soil;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getClimate() {
        return this.climate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param climate
     */
    public void setClimate(String climate) {
        this.climate = climate;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getOrganismResourcesForest() {
        return this.organismResourcesForest;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organismResourcesForest
     */
    public void setOrganismResourcesForest(String organismResourcesForest) {
        this.organismResourcesForest = organismResourcesForest;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getOrganismResourcesVegeType() {
        return this.organismResourcesVegeType;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organismResourcesVegeType
     */
    public void setOrganismResourcesVegeType(String organismResourcesVegeType) {
        this.organismResourcesVegeType = organismResourcesVegeType;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getOrganismResourcesPlant() {
        return this.organismResourcesPlant;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organismResourcesPlant
     */
    public void setOrganismResourcesPlant(String organismResourcesPlant) {
        this.organismResourcesPlant = organismResourcesPlant;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getOrganismResourcesAnimal() {
        return this.organismResourcesAnimal;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param organismResourcesAnimal
     */
    public void setOrganismResourcesAnimal(String organismResourcesAnimal) {
        this.organismResourcesAnimal = organismResourcesAnimal;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getTourismResources() {
        return this.tourismResources;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param tourismResources
     */
    public void setTourismResources(String tourismResources) {
        this.tourismResources = tourismResources;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getSocialEconomy() {
        return this.socialEconomy;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param socialEconomy
     */
    public void setSocialEconomy(String socialEconomy) {
        this.socialEconomy = socialEconomy;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    public String getCreator() {
        return this.creator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param creator
     */
    public void setCreator(String creator) {
        this.creator = creator;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Set
     */
    public Set<EcosystemImage> getImages() {
        return this.images;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param images
     */
    public void setImages(Set<EcosystemImage> images) {
        this.images = images;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return String
     */
    @Override
    public String toString() {
        return "Ecosystem {" + "id='" + id + '\'' +
                ", version='" + version + '\'' +
                ", name='" + name + '\'' +
                ", administrativeLocation='" + administrativeLocation + '\'' +
                ", area='" + area + '\'' +
                ", maintained='" + maintained + '\'' +
                ", type=" + type + '\'' +
                ", category='" + category + '\'' +
                ", currentLevel='" + currentLevel + '\'' +
                ", administrativeDepartment='" + administrativeDepartment + '\'' +
                ", createDate='" + createDate + '\'' +
                ", approver='" + approver + '\'' +
                ", currentLevelApproveDate='" + currentLevelApproveDate + '\'' +
                ", coordinate='" + coordinate + '\'' +
                ", administrativeRegion='" + administrativeRegion + '\'' +
                ", geologyStructure='" + geologyStructure + '\'' +
                ", geologyLithology='" + geologyLithology + '\'' +
                ", geologyLandform='" + geologyLandform + '\'' +
                ", geologyHydrogeology='" + geologyHydrogeology + '\'' +
                ", soil='" + soil + '\'' +
                ", climate='" + climate + '\'' +
                ", organismResourcesForest='" + organismResourcesForest + '\'' +
                ", organismResourcesVegeType='" + organismResourcesVegeType + '\'' +
                ", organismResourcesPlant='" + organismResourcesPlant + '\'' +
                ", organismResourcesAnimal='" + organismResourcesAnimal + '\'' +
                ", tourismResources='" + tourismResources + '\'' +
                ", socialEconomy='" + socialEconomy + '\'' +
                ", creator='" + creator + '\'' +
                ", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' +
                ", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' +
                "}" + super.toString();
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToAdd
     */
    public void addToImages(Iterable<EcosystemImage> imagesToAdd) {
        Assert.notNull(imagesToAdd, ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE);
        for (EcosystemImage item : imagesToAdd) {
            this.images.add(item);
            item.setEcosystem(this);
        }
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param imagesToRemove
     */
    public void removeFromImages(Iterable<EcosystemImage> imagesToRemove) {
        Assert.notNull(imagesToRemove, ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE);
        for (EcosystemImage item : imagesToRemove) {
            this.images.remove(item);
            item.setEcosystem(null);
        }
    }

    @PrePersist
    public void prePersist(){
        this.setInitial(ChineseInital.getFirstLetter(this.getName()));
    }

    @PreUpdate
    public void preUpdate(){
        this.setInitial(ChineseInital.getFirstLetter(this.getName()));
    }
}
